// ==UserScript==
// @name       YE功能增强.02 - [淘宝、天猫]
// @description
// @copyright  2014+, AsionTang
// @namespace  http://AsionTang.CN
// @version    220220.24.04.041
// @iconURL    http://taobao.com/favicon.ico
// @downloadURL   https://gitee.com/AsionTang/52.ScriptLibrary/raw/master/YeJS/02.TaoBao.user.js
// @require     https://gitee.com/AsionTang/52.ScriptLibrary/raw/master/YeJS/00.Utils.js
// @require     https://gitee.com/AsionTang/52.ScriptLibrary/raw/master/YeJS/00.Utils.SuiShouJi.js
// @match      *://*.taobao.com/*
// @match      *://*.tmall.com/*
// @match      *://*.95095.com/*
// @match      *://*.alipay.com/*
// @match      *://*.alipay.cn/*
// @match      *://*.alimama.cn/*
// @match      *://*.alimama.com/*
// @match      *://*.etao.com/*
// @run-at     document-end
// @grant      unsafeWindow
// @grant      GM_setClipboard
// @grant      GM_openInTab
// ==/UserScript==
// @Formatter   TypeScript and JavaScript Language Features

var YeScript = YeScript || {};
//var YE_IS_DEBUG = true;

(function () {
    if (!isLocationHrefContainsAll('cart.taobao.com'))
        return;
    //================================================================================
    console.log("024.淘宝购物车界面自动计算单价");
    //================================================================================
    window.Ye_024_setIntervalId = setInterval(function () {
        document.onclick = document_onclick;
    }, 1000);
    document.onclick = document_onclick;

    function document_onclick() //
    {
        clearInterval(window.Ye_024_setIntervalId);

        var countRegexE = document.querySelector('#q.search-combobox-input');
        var countRegex = countRegexE.value;
        if (!countRegex)
            countRegexE.value = countRegex = '(\\d+)只';

        var items = document.querySelectorAll('#J_OrderList .J_ItemBody ');
        for (var i = 0; i < items.length; i++) {
            var item = items[i];

            var productInfo = '';
            {
                var txtE = item.querySelector('.item-basic-info');
                productInfo += (txtE.innerText);
                var txtE = item.querySelector('.item-props');
                productInfo += (txtE.innerText);
            }
            console.log(productInfo);

            var count = 0.0;
            {
                count = getNumber(new RegExp(countRegex, 'gm'), productInfo);
            }
            console.log(count);

            var price = 0;
            {
                var txtE = item.querySelector('.J_Price.price-now');
                price = toNumber(txtE.innerText);
            }
            console.log(price);

            var unitPrice = price / count;
            console.log(unitPrice.toFixed(2));

            item.querySelector('.J_ItemLottery').innerText = '单价:' + unitPrice.toFixed(3);
        }
    }
}
)();

(function () //
{
    if (!isLocationHrefContainsAll('etao'))
        return;
    //================================================================================
    console.log("023.一淘搜索界面支持按返利排序和价格筛选");
    //================================================================================
    window.YeIntervalId = setInterval(function () //
    {
        document.onclick = onclick;
    }, 1000);
    function onclick() //0
    {
        //防止换页失效？
        //clearInterval(window.YeIntervalId);
        var eJ_minPrice = document.getElementById('J_minPrice');
        var minPrice = toNumber(eJ_minPrice.value);

        var eJ_maxPrice = document.getElementById('J_maxPrice');
        var maxPrice = toNumber(eJ_maxPrice.value);

        if (isNaN(minPrice)) //
        {
            var yeMinPrice = toNumber(localStorage.getItem('YeMinPrice'));
            if (!isNaN(yeMinPrice) && yeMinPrice > 0) //
            {
                //页面没限制时，自动恢复上次配置。
                eJ_minPrice.value = yeMinPrice;
                minPrice = yeMinPrice;
            }
        } else //
        {
            //当页面有限制值时，优先使用页面的。
            localStorage.setItem('YeMinPrice', minPrice);
        }

        if (isNaN(maxPrice)) //
        {
            var yeMaxPrice = toNumber(localStorage.getItem('YeMaxPrice'));
            if (!isNaN(yeMaxPrice) && yeMaxPrice > 0) //
            {
                //页面没限制时，自动恢复上次配置。
                eJ_maxPrice.value = yeMaxPrice;
                maxPrice = yeMaxPrice;
            }
        } else //
        {
            //当页面有限制值时，优先使用页面的。
            localStorage.setItem('YeMaxPrice', maxPrice);
        }

        resortAndFilterPrice(minPrice, maxPrice);
    }

    function resortAndFilterPrice(minPrice, maxPrice) //
    {
        var ux = [];
        var items = document.querySelectorAll('.rebate');
        for (var i = 0; i < items.length; i++) //
        {
            var item = items[i];
            var fanli = toNumber(item.innerText);
            var li = getParentElementByTagName(item, 'li');

            //过滤价格上下限制。
            var price = toNumber(li.querySelector('.current-price-data').innerText);
            if (!isNaN(minPrice) && minPrice > 0)
                if (price < minPrice)
                    continue;
            if (!isNaN(maxPrice) && maxPrice > 0)
                if (price > maxPrice)
                    continue;

            //
            var tmp = {};
            tmp.dom = li;
            tmp.title = fanli;
            //
            ux.push(tmp);
        }
        ux.sort(function (a, b) //
        {
            return b.title - a.title;
        });
        var ul = getParentElementByTagName(items[0], 'ul');
        //移除原先顺序错乱的li内容
        while (ul.firstChild)
            ul.removeChild(ul.firstChild);
        //再添加排序好的li内容
        for (var j = 0; j < ux.length; j++)
            ul.append(ux[j].dom);
    }
}
)();

(function () //
{
    if (!isLocationHrefContainsAll('taobao', 'item.htm'))
        return;
    //================================================================================
    console.log("022.将淘宝图片预览界面悬浮起来直到滚动到详情页，方便多个选项快速查看不用滚动到上方菜看得见");
    //================================================================================
    function hanlder() //
    {
        console.log('Hanlde the scroll event.');
        var price = document.querySelector('#J_PromoPrice');
        if (!price.leftOld)
            price.leftOld = price.getClientRects()[0].left;

        var title = document.querySelector('.tb-main-title');

        var g = document.querySelector('.tb-gallery');
        var h = g.getClientRects()[0].height;

        if (title.getClientRects()[0].top > 0 || document.querySelector('#J_TabBarWrap').getClientRects()[0].top <= h) {
            price.style.position = 'relative';
            price.style.top = '';
            price.style.left = '';

            g.style.position = 'relative';
            g.style.top = '';
            //g.style.marginLeft = '-100%';
        } else {
            price.style.position = 'fixed';
            price.style.top = '0px';
            price.style.left = price.leftOld + 'px';

            g.style.position = 'fixed';
            g.style.top = '0px';
            g.style.marginLeft = '0px';
        }
    }
    //[防抖动、节流阀与 rAF - 前端 - 掘金](https://juejin.im/entry/5947ae465c497d006bf6e6c4)
    window.addEventListener('scroll', hanlder);
}
)();

(function () //
{
    if (!isLocationHrefContainsAll('tmall', 'item.htm'))
        return;
    //================================================================================
    console.log("021.将天猫图片预览界面悬浮起来直到滚动到详情页，方便多个选项快速查看不用滚动到上方菜看得见");
    //================================================================================
    function hanlder() //
    {
        console.log('Hanlde the scroll event.');
        var price = document.querySelector('.tm-fcs-panel');
        if (!price.leftOld)
            price.leftOld = price.getClientRects()[0].left;

        var title = document.querySelector('.tb-detail-hd');

        var g = document.querySelector('.tb-gallery');
        var h = g.getClientRects()[0].height;

        if (title.getClientRects()[0].top > 0 || document.querySelector('#J_TabBarBox').getClientRects()[0].top <= h / 2) {
            price.style.position = 'relative';
            price.style.top = '';
            price.style.left = '';

            g.style.position = 'relative';
            g.style.top = '';
            g.style.marginLeft = '-100%';
        } else {
            price.style.position = 'fixed';
            price.style.top = '0px';
            price.style.left = price.leftOld + 'px';

            g.style.position = 'fixed';
            g.style.top = '0px';
            g.style.marginLeft = '0px';
        }
    }
    //[防抖动、节流阀与 rAF - 前端 - 掘金](https://juejin.im/entry/5947ae465c497d006bf6e6c4)
    window.addEventListener('scroll', hanlder);
}
)();

(function () //
{
    if (!isLocationHrefContainsAll('tmall', 'item.htm'))
        return;
    //================================================================================
    console.log("020.将天猫分类项的图片和文字都显示出来，方便快速寻找合适的项，否则得点击每个图片看");
    //================================================================================
    document.onclick = function () //
    {
        document.querySelectorAll('UL.J_TSaleProp li').forEach(function (e) //
        {
            //将Li不居左
            e.style.float = 'none';
            e.style.display = 'flex';

            //将图片居左显示，默认居中
            var a = e.getElementsByTagName('a')[0];
            a.style.backgroundPosition = 'left';

            //将文字显示出来，并居左对齐显示。
            var span = e.getElementsByTagName('span')[0];
            span.style.display = 'flex';
            span.style.marginLeft = '42px';
            span.style.textIndent = '0px';
        });
    }
}
)();

(function () //
{
    if (!isLocationHrefContainsAll('taobao', 'item.htm'))
        return;
    //================================================================================
    console.log("020.将天猫分类项的图片和文字都显示出来，方便快速寻找合适的项，否则得点击每个图片看");
    //================================================================================
    document.onclick = function () //
    {
        document.querySelectorAll('#J_isku li').forEach(function (e) //
        {
            //将Li不居左
            e.style.float = 'none';

            //将图片居左显示，默认居中
            var a = e.getElementsByTagName('a')[0];
            a.style.backgroundPosition = 'left';

            //将文字显示出来，并居左对齐显示。
            var span = e.getElementsByTagName('span')[0];
            span.style.display = 'flex';
            span.style.marginLeft = '36px';
        });
    }
}
)();

(function () //
{
    if (!isLocationHrefContainsAll('taobao', 'item.htm'))
        return;
    //================================================================================
    console.log("019.将淘宝分类项的图片和文字都显示出来，方便快速寻找合适的项，否则得点击每个图片看");
    //================================================================================
    document.onclick = function () //
    {
        document.querySelectorAll('#J_isku li').forEach(function (e) //
        {
            //将Li不居左
            e.style.float = 'none';

            //将图片居左显示，默认居中
            var a = e.getElementsByTagName('a')[0];
            a.style.backgroundPosition = 'left';

            //将文字显示出来，并居左对齐显示。
            var span = e.getElementsByTagName('span')[0];
            span.style.display = 'flex';
            span.style.marginLeft = '36px';
        });
    }
}
)();

(function () {
    if (!isLocationHrefContainsAll('taobao', 'trade_order_detail'))
        return;
    //================================================================
    var t = '18.淘宝订单详情 支持双击明细自动录入到随手记'
    //================================================================
    document.onclick = function () //
    {
        //不要重置掉此Click事件,以便在翻页时局部刷新列表后,还能够支持绑定事件.
        //document.onclick = null;
        console.log(t);
        var items = document.querySelectorAll('.order-item');
        for (var i = 0; i < items.length; i++) //
        {
            var item = items[i];
            item.ondblclick = function (e) //
            {
                //====================================================================
                // 业务代码区
                //====================================================================

                var tr = getParentElementByTagName(e.srcElement, 'TR');

                //测试地址
                //https://trade.taobao.com/trade/detail/trade_order_detail.htm?biz_order_id=399696257725964637

                //时间
                var time = toPureDateTime(document.querySelectorAll('#detail-panel div[class^="order-info-container"] span[class*="content"]')[2].innerText);

                //成交时间
                var timeFinish = toPureDateTime(document.querySelectorAll('#detail-panel div[class^="order-info-container"] span[class*="content"]')[4]?.innerText??'');

                //商品总价支付信息 63.51(使用129淘金币，抵扣1.29元)(快递: 0.00)
                //NO：不能用 toPureName 函数处理，因为会剔除括号里的所有文本。
                var totalPayInfo = document.querySelector('#detail-panel div[class|="pay-info"]').innerText.replace(/\n/gm, ' ');

                //卖家已为您的运费投保，最高赔付25元 详情>>\n订单总金额：63.51 元
                var totalAccountText = toPureName(document.querySelector('#detail-panel div[class*="item-detail"] div[class*="pay-info"]').innerText);
                var totalAccount = getNumber(/总金额：(\d+.\d+) 元/g, totalAccountText);
                if (!totalAccount)
                    totalAccount = getNumber(/订单总价：(\d+.\d+) 元/g, totalAccountText);
                if (!totalAccount)
                    totalAccount = getNumber(/商品总价：￥(\d+.\d+)/g, totalAccountText);

                //备注
                var memo = '';
                {
                    memo += '【' + time.substr(0, 10) + '淘宝购物￥' + totalAccount + '】';
                    memo += totalPayInfo;

                    memo += ' 名称：' + toPureName(tr.children[0].innerText) + ' ' + toPureName(tr.children[1].innerText);
                    memo += ' 售价：' + toPureName(tr.children[4].innerText);
                    memo += ' 数量：' + toPureName(tr.children[5].innerText);

                    memo = memo.replace(/\.00/gm, '');

                    console.log(memo);
                }

                //猜测支出分类
                {
                    //猜测支出分类
                    var category = getPayoutCategoryByGuess(memo);

                    //售价（记支出）
                    var price = toNumber(tr.children[4].innerText);
                    var count = toNumber(tr.children[5].innerText);

                    //从各种暂付金支出
                    var account = "15654917756";

                    //记账时间:默认=收货时间, 否则等于当月最后一天;
                    var recordTime = timeFinish;
                    if (!timeFinish)
                        recordTime = getTheLastSecondDateTimeOfMonth(time);

                    //统一记录为:当月30号的支出，并设置为【日用，保健居多】，从各种暂付金支出。
                    savePayoutRecord(category, account, price * count, recordTime, memo);
                }

                //当在此页面 首次 记账时,才需要这个订单的总的 优惠部分记一次. 下次再记别的商品时,没必要再记录一次 优惠部分了.
                document.isHadRecordTotalOne = document.isHadRecordTotalOne || false;
                if (document.isHadRecordTotalOne)
                    return;
                document.isHadRecordTotalOne = true;

                //当检测到淘金币抵扣时，需要额外记录一份收入 淘金币抵扣：-￥1.12
                var totalAccountTaoJinBi = getNumberEx(/淘金币抵扣：-￥(\d+\.\d+)/g, totalPayInfo);
                if (totalAccountTaoJinBi > 0)//
                {
                    //收入 - 淘金币
                    var category = "2001693945";
                    //暂付金
                    var account = "15654917756";
                    var price = totalAccountTaoJinBi;
                    saveIncomeRecord(category, account, price, time, memo);
                }

                //当检测到优惠金额 != 淘金币抵扣时，需要额外记录一份优惠的收入
                {
                    //获取实际付款金额: 实付款：￥29.94 元
                    var totalPay = getNumber(/实付款：￥(\d+.\d+) 元/g, totalAccountText);

                    //优惠金额 = 商品总价 - 实际付款
                    var youHui = totalAccount - totalPay;

                    var diff = youHui - totalAccountTaoJinBi;
                    if (diff > 0)//
                    {
                        //收入 - 优惠
                        var category = "20042968674";
                        //暂付金
                        var account = "15654917756";
                        var price = diff;
                        saveIncomeRecord(category, account, price, time, memo);
                    }
                }
            }
        }
    }
}
)();

(function () {
    if (!isLocationHrefContainsAll('tmall', 'orderDetail'))
        return;
    //================================================================
    // 17.天猫详情 支持双击明细自动录入到随手记
    //================================================================
    document.onclick = function () //
    {
        //不要重置掉此Click事件,以便在翻页时局部刷新列表后,还能够支持绑定事件.
        //document.onclick = null;
        console.log("15.天猫详情 支持双击明细自动录入到随手记");
        var items = document.querySelectorAll('#appOrders tr');
        for (var i = 1; i < items.length; i++) //
        {
            var item = items[i];
            item.ondblclick = function (e) //
            {
                //====================================================================
                // 业务代码区
                //====================================================================
                var steps = document.querySelectorAll('#appStepbar .step-time > .step-time-wraper');
                var time = toPureDateTime(steps[1].innerText);

                //取出确认收货的时间.
                var timeFinish;
                if (steps.length >= 4)//
                    timeFinish = toPureDateTime(document.querySelectorAll('#appStepbar .step-time > .step-time-wraper')[3].innerText);

                var tr = getParentElementByTagName(e.srcElement, 'TR');

                //支付总金额
                var totalPayInfo = '';
                var totalAccount = '';
                var orderInfos = document.querySelectorAll('#appAmount .total-count-line span.mixture');
                for (var i = 0; i < orderInfos.length; i++) //
                {
                    if (orderInfos[i].innerText.indexOf('商品总价') > -1)
                        totalAccount = orderInfos[i].innerText;
                    else
                        totalPayInfo += ' ' + toPureName(orderInfos[i].innerText);
                }
                totalAccount = toNumber(totalAccount);

                //备注
                var memo = '';
                {
                    memo += '【' + time.substr(0, 10) + '天猫购物￥' + totalAccount + '】';
                    memo += totalPayInfo;

                    memo += ' 名称：' + toPureName(tr.children[0].innerText);
                    memo += ' 售价：' + toPureName(tr.children[1].innerText);
                    memo += ' 数量：' + toPureName(tr.children[2].innerText);

                    memo = memo.replace(/\.00/gm, '');

                    console.log(memo);
                }

                //记录支出
                {
                    //猜测支出分类
                    var category = getPayoutCategoryByGuess(memo);

                    //售价（记支出）
                    var price = toNumber(tr.children[1].innerText);
                    var count = toNumber(tr.children[2].innerText);

                    //从各种暂付金支出
                    var account = "15654917756";

                    //记账时间:默认=收货时间, 否则等于当月最后一天;
                    var recordTime = timeFinish;
                    if (!timeFinish)
                        recordTime = getTheLastSecondDateTimeOfMonth(time);

                    //统一记录为:当月30号的支出，并设置为【日用，保健居多】，从各种暂付金支出。
                    savePayoutRecord(category, account, price * count, recordTime, memo);
                }

                //当在此页面 首次 记账时,才需要这个订单的总的 优惠部分记一次. 下次再记别的商品时,没必要再记录一次 优惠部分了.
                document.isHadRecordTotalOne = document.isHadRecordTotalOne || false;
                if (document.isHadRecordTotalOne)
                    return;
                document.isHadRecordTotalOne = true;

                //当检测到淘金币抵扣时，需要额外记录一份收入
                //运费：￥0 一淘立减优惠：-￥0.10 红包：-￥3.80 实付款：￥7
                var totalAccountTaoJinBi = getNumberEx(/淘金币抵扣：-￥(\d+\.\d+)/g, totalPayInfo);
                if (totalAccountTaoJinBi > 0) //
                {
                    //收入 - 淘金币
                    var category = "2001693945";
                    //暂付金
                    var account = "15654917756";
                    var price = totalAccountTaoJinBi;
                    saveIncomeRecord(category, account, price, time, memo);
                }

                //当检测到优惠金额 != 淘金币抵扣时，需要额外记录一份优惠的收入
                {
                    //获取实际付款金额:
                    //运费：￥0 一淘立减优惠：-￥0.10 红包：-￥3.80 实付款：￥7
                    var totalPay = getNumberEx(/实付款：￥(\d+.\d+)/g, totalPayInfo);

                    //优惠金额 = 商品总价 - 实际付款
                    var youHui = totalAccount - totalPay;

                    var diff = youHui - totalAccountTaoJinBi;
                    if (diff > 0) {
                        //收入 - 优惠
                        var category = "20042968674";
                        //暂付金
                        var account = "15654917756";
                        var price = diff;
                        saveIncomeRecord(category, account, price, time, memo);
                    }
                }
            }
        }
    }
}
)();

(function () {
    if (!isLocationHrefContainsAll('alimama', 'search', 'queryType=2'))
        return;
    //================================================================================
    // 16.在阿里妈妈 单品推广 界面支持在立即推广界面直接在当前界面打开商品界面
    //================================================================================
    //     window.Ye_14_setIntervalId = setInterval(document_onclick, 1000);
    document.onclick = document_onclick;
    function document_onclick() {
        //场景2:当点击"立即推广"之后,自动点击弹出来的对话里的“确定”按钮
        var dialog = document.querySelector('.dialog.dialog-singleton.dialog-top');

        //场景1:初次打开时,检测到检索结果只有1个结果时,则自动点击"立即推广".
        var totalSearchCount = new Number(document.querySelector('#J_category_filter .top-nav-text > span').innerText);
        if (totalSearchCount == 1)
            autoClickLiJiTuiGuang();
        return;

        var btnClose = document.querySelector('#magix_vf_code button:last-child');
        if (!btnClose) {
            console.debug('找不到“立即推广”对话框里的“关闭”按钮');
            return;
        }
        if (window.Ye_14_HadAddbtnOpenCurrentPage) {
            console.log('已经添加 btnOpenCurrentPage 成功,不再执行.');
            return;
        }
        window.Ye_14_HadAddbtnOpenCurrentPage = true;

        var btnOpenCurrentPage = document.createElement('button');
        btnOpenCurrentPage.className = 'btn btn-brand w100 mr10';
        btnOpenCurrentPage.innerText = '当页直接打开'
        btnOpenCurrentPage.onclick = function () {
            window.open(document.querySelector('#clipboard-target').value, "_self");
        }
        btnClose.parentNode.insertBefore(btnOpenCurrentPage, btnClose);
    }
    function autoClickLiJiTuiGuang() {
        if (window.Ye_14_HadDone_autoClickLiJiTuiGuang) {
            console.log('已经点击检索到的唯一产品的“立即推广”按钮完毕.');
            return;
        }
        var btn = document.querySelector('#J_search_results .box-btn-group > .box-btn-left');
        if (!btn) {
            console.error('无法找到检索到的唯一产品的“立即推广”按钮！');
            return;
        }
        window.Ye_14_HadDone_autoClickLiJiTuiGuang = true;
        btn.click();
        console.log('自动点击检索到的唯一产品的“立即推广”按钮完毕.');
    }
}
)();

(function () {
    if (!isLocationHrefContainsAll('alipay', 'record/detail/simpleDetail.htm'/*, 'bizType=TRADE OR PREAUTHPAY'*/))
        return;
    //================================================================
    // 15.支付宝 账单明细界面支持双击快速记账
    //================================================================
    document.ondblclick = function () //
    {
        //不要重置掉此Click事件,以便在翻页时局部刷新列表后,还能够支持绑定事件.
        //document.onclick = null;
        console.log("15.支付宝 账单明细界面支持双击快速记账");

        //====================================================================
        // 业务代码区
        //====================================================================
        var time = document.querySelector('#fundDom > div.fund-box > div > span.fn-left').innerText;
        time = toPureDateTime(time);
        console.log(time);

        var memo = document.querySelector('#fundDom > div.trade-info > p:nth-child(1) > span').innerText;
        memo = toPureName(memo);
        console.log('支出内容：' + memo);
        var duiFangMingChen = document.querySelector('#fundDom > div.trade-info > p.info-item > span.opposite').innerText;
        duiFangMingChen = toPureName(duiFangMingChen);
        console.log('对方帐号：' + duiFangMingChen);
        memo = memo + '; ' + duiFangMingChen;

        //判断今日离谁的账单日最长,就用谁.
        var accountName = document.querySelector('#fundDom > div.fund-box > table > tbody > tr > td > div > span.fundTool.tb-elem-align-left > a');
        //优先取带 A 标签的名称,例子如下:(同时存在优惠和信用卡支付时,应该以A标签的名称为准.)
        //https://consumeprod.alipay.com/record/detail/simpleDetail.htm?bizType=TRADE&bizInNo=2017061221001001630245287375&gmtBizCreate=20170612200202
        if (!accountName) {
            var tools = document.querySelectorAll('#fundDom > div.fund-box > table > tbody > tr > td > div > span.fundTool.tb-elem-align-left');
            if (!tools)//
            {
                console.error('获取账户名称失败。');
                return;
            }
            if (tools.length == 1)
                //当从余额宝走的时候,取A标签是取不到的.所以换一种.
                //https://consumeprod.alipay.com/record/detail/simpleDetail.htm?bizType=TRADE&bizInNo=2017061921001001630258953204&gmtBizCreate=20170619171114
                accountName = tools[0];
            else if (tools.length == 2)
                //当使用花呗支付时同时存在优惠时，优先取花呗的名称。
                //https://consumeprod.alipay.com/record/detail/simpleDetail.htm?bizType=TRADE&bizInNo=2019031822001403630593539392&gmtBizCreate=20190318175936
                accountName = tools[1];
            else//
            {
                console.error('获取到的账户名称大于2个！');
                return;
            }
        }
        accountName = accountName.innerText;
        console.log('accountName:' + accountName);

        //获取 订单金额
        var order_amount = document.querySelector('#fundDom .order-amount').innerText;
        order_amount = toNumber(order_amount);
        console.log(order_amount);

        //计算 优惠抵扣
        var discount_amount = 0;
        if (document.querySelector('#fundDom .discount-amount-title')) //
        {
            discount_amount = document.querySelector('#fundDom .discount-amount').innerText;
            discount_amount = toNumber(discount_amount);
            console.log('discount_amount:' + discount_amount);
        }

        //获取 实付金额
        var real_amount = document.querySelector('#fundDom .real-amount').innerText;
        real_amount = toNumber(real_amount);
        console.assert(real_amount === order_amount - discount_amount, '页面获取的实付金额', real_amount, '居然不等于计算得来的实付金额', order_amount - discount_amount);

        //获取当前帐号名称以便区分是谁的花呗账户
        var userName = document.querySelector('#J-nav-top .fn-right span').innerText;
        var isDM = userName.indexOf('冬梅') > -1;

        //检测是否是特殊业务，需要直接记录为支出
        var isShangHaiDiTie = memo.indexOf('上海地铁乘车扣款') > -1;
        var isXiangHuBao = memo.indexOf('相互宝') > -1;
        var isTe = isShangHaiDiTie || isXiangHuBao;

        //实付金额 == 订单金额 - 优惠抵扣 时: 需要多记录一笔收入到暂付金
        if (discount_amount > 0) //
        {
            //获取优惠抵扣名称
            var fundTool = document.querySelector('#fundDom .detail-list ');
            fundTool = fundTool ? fundTool.innerText : '';

            //额外收入 - 优惠
            var category = "20042968674";
            //各种暂付金
            var account = "15654917756";
            var price = discount_amount;
            var real_memo = isTe ? memo : '【' + time.substr(0, 10) + '网购￥' + order_amount + '】' + memo;
            real_memo += ' 优惠抵扣:' + fundTool;
            saveIncomeRecord(category, account, price, time, real_memo);
        }

        //实付金额 == 订单金额 时: 记录一笔XX账户转账到暂付金即可.
        //if(real_amount === order_amount)//
        //各种暂付金
        var in_account = "15654917756";
        var out_account = getBestOutAccountByName(userName + accountName);

        var category = "0";
        var account = in_account + "-" + out_account;
        var price = real_amount;
        var real_memo = isTe ? memo : '【' + time.substr(0, 10) + '网购￥' + order_amount + '】' + memo;
        if (price > 0) {
            //当 上海地铁乘车扣款 没有优惠折扣时,则不记录转账,改为直接支出.
            if (!isTe || discount_amount > 0)
                saveTransferRecord(category, account, price, time, real_memo);
        }
        //检测是否是特殊业务，需要直接记录为支出
        if (!isTe)
            return;

        //假如是 上海地铁乘车扣款 需要直接记录一笔支出
        if (isShangHaiDiTie) //
        {
            //地铁
            var category = '175369643585';

            //当 上海地铁乘车扣款 没有优惠折扣时,则不记录转账,改为直接支出.
            if (discount_amount == 0)
                var account = out_account;
            else
                //各种暂付金
                var account = "15654917756";
            var price = order_amount;
            savePayoutRecord(category, account, price, time, memo);
        }

        //假如是 相互保 需要直接记录一笔支出
        if (isXiangHuBao) //
        {
            //意外险
            var category = '351339165';

            //当 没有优惠折扣时,则不记录转账,改为直接支出.
            if (discount_amount == 0)
                var account = out_account;
            else
                //各种暂付金
                var account = "15654917756";
            var price = order_amount;
            savePayoutRecord(category, account, price, time, memo);
        }
    }
}
)();

(function () {
    if (!isLocationHrefContainsAll('alipay', '/portal/i.htm'))
        return;
    //================================================================
    // 14.支付宝 支持双击明细自动录入到随手记
    //================================================================
    document.onclick = function () {
        //不要重置掉此Click事件,以便在翻页时局部刷新列表后,还能够支持绑定事件.
        //document.onclick = null;
        console.log("14.支付宝 支持双击明细自动录入到随手记");
        var items = document.getElementById('tradeRecordsIndex').getElementsByTagName('tr');
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            item.ondblclick = function (e) {
                //====================================================================
                // 业务代码区
                //====================================================================
                var tr = getParentElementByTagName(e.srcElement, 'TR');
                var time = tr.children[0].innerText;
                var memo = tr.children[2].innerText;
                console.log(memo);

                if (memo.indexOf('余额宝') != -1 && memo.indexOf('收益发放') != -1) {
                    //把利息入收入记录
                    var liXiRegex = new RegExp("([\\d\\.]+)", "gm");
                    var liXi = getNumber(liXiRegex, tr.children[3].innerText);
                    console.log('余额宝:' + liXi);

                    var category = "1770193156370";
                    var account = "244709340";
                    var price = liXi;
                    saveIncomeRecord(category, account, price, time, memo);
                } else if (memo.indexOf('兴全合润分级混合') != -1 && memo.indexOf('买入') != -1) {
                    //把定投记为转账记录
                    var liXiRegex = new RegExp("([\\d\\.]+)", "gm");
                    var liXi = getNumber(liXiRegex, tr.children[3].innerText);
                    console.log('定投:' + liXi);

                    var category = "0";
                    //支付宝-轻定投
                    var in_account = "262519236";
                    //YE 余额宝
                    var out_account = "244709340";
                    var account = in_account + "-" + out_account;
                    var price = liXi;
                    saveTransferRecord(category, account, price, time, memo);
                } else {
                    showToastAtTitle('点击了不在预期范围内的行数据:' + tr.innerText);
                    console.log('点击了不在预期范围内的行数据:' + tr.innerText);
                    console.dir(tr);
                }
            }
        }
    }
}
)();

(function () {
    //0.01元兑 https://h5.m.taobao.com/app/tjb/www/coin-exchange/index.html
    if (window.location.pathname != '/app/tjb/www/coin-exchange/index.html')
        return;
    //================================================================================
    // 13.在H5淘金币0.01元兑界面,剔除掉"已兑换"的商品
    //================================================================================
    setInterval(function () {
        var items = document.querySelectorAll('.J_CommodityWrap .item');
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.innerText.indexOf('已兑完') > -1) {
                //方法一:
                //（缺点：有的情况无法隐藏。）
                item.hidden = true;
                //方法二:
                //（缺点：有的布局会错乱。）
                //collapse
                //item.style.visibility = 'collapse';
                //item.style.height = '0px';
            }
        }
    }, 1000);
}
)();

(function () {
    if (location.host.indexOf('taobao') == -1 || location.pathname.indexOf('search') == -1)
        return;
    //================================================================================
    // 12.增强淘宝搜索功能:支持强制过滤需要排除的关键字.
    //================================================================================
    var tag = 'Ye--------------：';
    document.ondblclick = function () {
        //
        //找到搜索框的值
        var input_box = document.getElementsByClassName('search-combobox-input')[0];
        if (!input_box) {
            console.error(tag + "找不到搜索框!");
            return;
        }
        var inputString = input_box.value;
        //
        //找到需要排除的关键字
        var regExp = / -([^ ]+)/g;
        var excludeItems = inputString.match(regExp);
        if (!excludeItems || excludeItems.length == 0) {
            console.error(tag + "找不到需要过滤的关键词!");
            return;
        }
        //剔掉排除关键字的前缀 -得到真正的关键字.
        for (var i = 0; i < excludeItems.length; i++) {
            excludeItems[i] = excludeItems[i].replace(' -', '');
        }
        //
        //排除方法.
        function isNeedExclude(pName) {
            for (var i = 0; i < excludeItems.length; i++) {
                if (pName.indexOf(excludeItems[i]) > -1)
                    return true;
            }
            return false;
        }
        //
        //找到所有的产品列表,然后进行排除检测.
        var louWangZhiYu = 0;
        var items = document.querySelectorAll('#mainsrp-itemlist .items .item');
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            var title = item.getElementsByClassName('title')[0];
            if (!title) {
                console.error(tag + "找不到标题:");
                console.dir(item);
                continue;
            }
            if (isNeedExclude(title.innerText)) {
                louWangZhiYu++;
                console.log(title.innerText);
                title.style.backgroundColor = 'yellow';
            }
        }
        if (louWangZhiYu > 0)
            console.warn(tag + '漏网之鱼:' + louWangZhiYu);
        else
            console.log(tag + '很好,没有漏网之鱼.');
    }
    console.log(tag + "增强型关键字排除功能加载完毕!双击空白处即可触发.");
    var sb = document.querySelector('#J_HeaderSearchTab .selected');
    if (sb)
        sb.innerText = 'Ye✔';
    else
        document.title = 'Ye✔' + document.title;
}
)();

(function () {
    if (window.location.pathname != '/awp/core/detail.htm')
        return;
    //================================================================================
    // 11.在H5淘宝宝贝详情页 - 增加在电脑端网页打开的功能
    //================================================================================
    setTimeout(function () {
        var items = document.getElementsByClassName('category-entrance c-btn');
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            item.target = '_blank';
            item.innerText = '【===打开电脑端网页===】';
            item.href = 'https://item.taobao.com/item.htm' + window.location.search;
        }
    }, 500);
}
)();

(function () {
    if (window.location.pathname != '/vip/exchange-center.html'//兑换中心 https://h5.m.taobao.com/vip/exchange-center.html
        && window.location.pathname != '/app/tjb/www/shop-exchange.html'//店铺兑换 https://h5.m.taobao.com/app/tjb/www/shop-exchange.html
    )
        return;
    //================================================================================
    // 10.在H5淘金币兑换界面,剔除掉"已兑换"的商品,并修改链接以新窗口的形式打开
    //================================================================================
    setInterval(function () {
        var items = document.getElementsByClassName('commodity-item');
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.innerText.indexOf('已兑完') > -1)
                item.hidden = true;
            else
                item.getElementsByClassName('co-link')[0].target = "_blank";
        }
    }, 1000);
}
)();

(function () {
    if (window.location.pathname != '/trade/detail/trade_item_detail.htm')
        return;
    //================================================================================
    // 09.在淘宝交易详情页 - 自动复制订单详情
    //================================================================================

    //一直向上获取指定Tag标签的父节点
    function getParentElementByTagName(e, tagName) {
        if (e.tagName.toUpperCase() == tagName.toUpperCase())
            return e;
        if (e.parentElement == null)
            return null;
        return getParentElementByTagName(e.parentElement, tagName);
    }
    var onItemClick = function (e) {
        //获取下单时间
        var times = document.getElementsByClassName('datetime');
        var orderTime = times.length>1 ? times[1].innerText : document.getElementsByClassName('confirm-time')[0].innerText;
        //2015-10-05 23:23:43
        orderTime = orderTime.substring(0, 10);

        //获取商家名称

        //获取订单总金额
        var priceItems = document.getElementsByClassName('order-price');
        var orderPrice = priceItems[2] ? priceItems[2] : priceItems[priceItems.length-1];
        var amount = orderPrice.innerText;
        amount = amount.replace(/¥/g, '');
        amount = amount.replace(/[\n ：:，]/g, '');
        amount = amount.replace(/\.00/g, '');
        amount = amount.replace('快递0', '包邮');

        //获得一行的商品信息
        var tr = getParentElementByTagName(e.srcElement, 'TR');

        //获取商品名称
        var pName = tr.getElementsByClassName('name')[0].innerText;
        pName = pName.replace('[交易快照]', '');
        pName = pName.replace(/[\n]/g, '');
        pName = pName.replace(/  /g, '');
        pName = pName.replace(/： /g, ':');
        pName = pName.replace(/此商品性质不支持7天退货/g, '');
        pName = pName.replace(/详情/g, '');
        pName = pName.replace(/包邮/g, '');

        //规格、颜色分类等信息

        //规格、颜色分类等信息
        var props = "";
        var propsEs = tr.getElementsByClassName('props');
        if (propsEs.length > 0) {
            props = propsEs[0].innerText;
            props = props.replace(/[\n]/g, '');
            props = props.replace(/: /g, ':');
        }

        //获取商品标价
        var price = tr.getElementsByClassName('price')[0].innerText;
        price = parseFloat(price);

        //获取下单数量
        var pNum = tr.getElementsByClassName('num')[0].innerText;
        pNum = parseInt(pNum);

        //获取商品优惠
        var youhui = tr.getElementsByClassName('discount')[0].innerText;
        youhui = youhui.replace(/[^\d\.]*/g, '');
        youhui = parseFloat(youhui);

        //计算商品实际价格 = (标价*数量 - 优惠)/数量
        if (!isNaN(youhui))
            price = (price * pNum - youhui) / pNum;

        //拼接成指定字符串显示。
        var info = '';
        info += '【' + orderTime + '网购￥' + amount + '】';
        info += pName + props;
        info += ' 价格:￥' + price.toFixed(2)
        info += '*' + pNum;

        console.dir(info);

        alert(info);

        GM_setClipboard(info, {
            type: 'text',
            mimetype: 'text/plain'
        });
    };

    //获取所有商品
    var items = document.getElementsByClassName('order-item');
    console.dir('商品数量：' + items.length);
    for (var i = 0; i < items.length; i++) {
        var item = items[i];
        var pTr = item;
        if (pTr)
            pTr.ondblclick = function (e) {
                try {
                    onItemClick(e);
                } catch (ex) {
                    console.dir(ex);
                    alert(ex);
                }
            }
    }
}
)();

(function () {
    if (window.location.pathname != '/coin/introduct.htm')
        return;
    document.ondblclick = function () {
        try {
            //================================================================================
            // 08.在“淘金币 - 赚金币”页面自动打开可以做的任务和隐藏不想做的任务
            //================================================================================

            var items = document.getElementsByClassName('sign-panel');

            //【购物领淘金币（40分钟有效）】
            var item = items[0];
            var innerText = item.innerText;
            var btns = item.getElementsByClassName('sign-bd-button');
            for (var j = 0; j < btns.length; j++) {
                var btn = btns[j];
                btn.click();
            }

            //【店铺签到领淘金币】
            var item = items[1];
            var btns = item.getElementsByClassName('sign-bd-button');
            for (var j = 0; j < btns.length; j++) {
                var btn = btns[j];
                btn.click();
            }

            //【收藏/分享送金币】
            var item = items[2];
            var deletedItems = deletedItems || [];
            var btns = item.getElementsByClassName('sign-bd-button');
            for (var j = 0; j < btns.length; j++) {
                var btn = btns[j];
                //只做“收藏本店得淘金币”的任务，其它分享本店商品得淘金币的任务放弃不做。
                if (btn.parentElement.innerText.indexOf('收藏本店') == -1) {
                    deletedItems.push(btn.parentElement.parentElement);
                    continue;
                }
                btn.click();
            }

            //【排除区域3里不需要的项】：
            var deletedItems = deletedItems || [];
            var items = document.getElementsByClassName('inte-item');
            for (var i = 0; i < items.length; i++) {
                var item = items[i];
                var title = item.getElementsByClassName('item-title')[0].innerText;

                if (title.indexOf('店铺签到领淘金币') > -1 || title.indexOf('手机淘宝领淘金币') > -1 || title.indexOf('每日签到领淘金币') > -1 || title.indexOf('购物送淘金币') > -1)
                    deletedItems.push(item);
                else {
                    var as = item.getElementsByTagName('a');
                    as[0].click();
                }
            }
            for (var i = 0; i < deletedItems.length; i++) {
                var item = deletedItems[i];
                item.parentElement.removeChild(item);
            }
        } catch (e) {
            console.error(e);
            alert(e.message);
        }
    }
}
)();

(function () {
    if (window.location.pathname != '/detail/orderDetail.htm')
        return;
    //================================================================================
    // 07.在天猫订单详情页 - 自动复制订单详情
    //================================================================================

    //一直向上获取指定Tag标签的父节点
    function getParentElementByTagName(e, tagName) {
        if (e.tagName.toUpperCase() == tagName.toUpperCase())
            return e;
        if (e.parentElement == null)
            return null;
        return getParentElementByTagName(e.parentElement, tagName);
    }
    var onItemClick = function (e) {
        //获得一行的商品信息
        var tr = getParentElementByTagName(e.srcElement, 'TR');

        var times = document.getElementsByClassName('step-time-wraper');

        //获取下单时间
        var orderTime = times[0].innerText;
        //2015-10-05 23:23:43
        orderTime = orderTime.substring(0, 10);

        //获取商家名称

        //获取订单总金额
        var amount = document.getElementsByClassName('total-count-num')[0].innerText;
        amount = amount.replace(/¥/g, '');
        amount = amount.replace(/[\n ()：]/g, '');
        amount = amount.replace(/\.00/g, '');

        //运费
        var yunfei = document.getElementsByClassName('header-content-logistics')[0].innerText
        yunfei = yunfei.replace(/[\n ()：]/g, '');
        yunfei = yunfei.replace(/\.00/g, '');
        yunfei = yunfei.replace('0快递', '包邮');
        yunfei = yunfei.replace(/(\d+)快递/g, '(邮费￥$1)');

        //获取商品名称和规格、颜色分类等信息
        var pName = tr.getElementsByClassName('header-item')[0].innerText;
        pName = pName.replace('[交易快照]', '');
        pName = pName.replace(/[\n]/g, '');
        pName = pName.replace(/  /g, '');
        pName = pName.replace(/： /g, ':');
        pName = pName.replace(/此商品性质不支持7天退货/g, '');
        pName = pName.replace(/详情/g, '');
        pName = pName.replace(/包邮/g, '');

        //获取下单数量
        var pNum = tr.getElementsByClassName('header-count')[0].innerText;
        pNum = parseInt(pNum);

        //获取商品标价
        var price = tr.getElementsByClassName('header-price')[0].innerText;
        price = parseFloat(price);

        //获取商品优惠
        var youhui = tr.getElementsByClassName('header-favorable')[0].innerText;
        youhui = youhui.replace(/[^\d\.]*/g, '');
        youhui = parseFloat(youhui);

        //计算商品实际价格 = (标价*数量 - 优惠)/数量
        if (!isNaN(youhui))
            price = (price * pNum - youhui) / pNum;

        //拼接成指定字符串显示。
        var info = '';
        info += '【' + orderTime + '网购￥' + amount + yunfei + '】';
        info += pName;
        info += ' 价格:￥' + price.toFixed(2)
        info += '*' + pNum;

        console.dir(info);

        prompt('', info);

        GM_setClipboard(info, {
            type: 'text',
            mimetype: 'text/plain'
        });
    };

    //获取所有商品
    var items = document.getElementsByClassName('header-item');
    console.dir('商品数量：' + (items.length - 1));
    for (var i = 0; i < items.length; i++) {
        var item = items[i];
        var pTr = getParentElementByTagName(item, 'tr');
        if (pTr)
            pTr.onclick = function (e) {
                try {
                    onItemClick(e);
                } catch (ex) {
                    console.dir(ex);
                    alert(ex);
                }
            }
                ;
    }
}
)();
(function () {
    if (window.location.pathname != '/trade/itemlist/list_bought_items.htm')
        return;
    //================================================================================
    // 06.在淘宝已买到的宝贝；自动复制订单详情
    //================================================================================
    //给所有订单区域绑定双击事件.
    setInterval(function () {
        var items = document.querySelectorAll('#J_bought_main table');
        for (var i = 0; i < items.length; i++) {
            var dingDan = items[i];
            if (dingDan.className.indexOf('head') > -1)
                continue;
            //
            dingDan.ondblclick = whenOnDingDanDbClick;
        }
    }, 1000);
    //===============================================================
    /*当双击订单区域时触发.*/
    function whenOnDingDanDbClick(e) {
        var dingDan = getMatchParentElement(e.srcElement, 'table');
        var clickedProductRow = getMatchParentElement(e.srcElement, 'tr');
        //获取:产品名称
        var _productName = getProductName(clickedProductRow);
        if (!_productName)
            //当双击的保险服务一行时,不做响应,因为此时无法找到产品名称.
            return;
        //获取:产品单价
        var priceItem = getProductPriceElement(clickedProductRow);
        var _price = priceItem.innerText;
        var priceDelItem = getProductPriceDeletedElement(clickedProductRow);
        //存在产品原价时,需要剔除掉.
        if (priceDelItem)
            _price = _price.replace(priceDelItem.innerText, '');
        _price = toNumber(_price);
        //获取:产品数量
        var _count = getProductCount(priceItem);
        _count = toNumber(_count);
        //获取:产品规格
        var _props = getProductProps(clickedProductRow);
        //获取:订单创建日期
        var _time = getOrderCreateTime(dingDan);
        //获取:订单运费
        var yunFeiSpan = getMatchInnerTextElement(dingDan.getElementsByTagName('span'), '运费');
        var yunFeiP = getMatchParentElement(yunFeiSpan, 'p');
        var _yunFei = toNumber(yunFeiP.innerText);
        //获取:订单总金额
        var orderTotal = yunFeiP.previousElementSibling.lastElementChild;
        var _totalPrice = toNumber(orderTotal.innerText);
        //================
        // 输出最终文本!!!
        //================
        var info = '';
        info += '【' + _time + '网购￥' + _totalPrice
        if (_yunFei == 0)
            info += '包邮';
        else
            info += '运费￥' + _yunFei;
        info += '】';
        info += _productName + _props;
        info += ' 价格:￥' + _price
        info += '*' + _count;
        console.dir(info);
        try {
            GM_setClipboard(info, {
                type: 'text',
                mimetype: 'text/plain'
            });
        } catch (e) {
            console.dir(e);
            window.prompt('┏━━━━━━━━━━━━━━━━━━━━━━━━┓\n\┃使用 Ctrl + C 复制 即可！           By:AsionTang┃\n\┗━━━━━━━━━━━━━━━━━━━━━━━━┛', info);
        }

        //一键记账功能.
        {
            //猜测支出分类
            var category = getPayoutCategoryByGuess(info);

            //售价（记支出）
            var price = _price;
            var count = _count;

            //从各种暂付金支出
            var account = "15654917756";

            //统一记录为:当月最后一日的支出，并设置为猜测的分类，从各种暂付金支出。
            savePayoutRecord(category, account, price * count, getTheLastSecondDateTimeOfMonth(_time), info);
        }
    }
    //===============================================================
    /*获取:产品名称*/
    function getProductName(e) {
        var aList = e.getElementsByTagName('A');
        for (var j = 0; j < aList.length; j++) {
            var innerText = aList[j].innerText;
            if (!innerText || innerText.length <= 6)
                continue;
            //
            var href = aList[j].href;
            if (!isProductItemDetailUrl(href))
                continue;
            //
            return innerText;
        }
    }
    /*获取:订单创建日期*/
    function getOrderCreateTime(e) {
        var tdList = e.getElementsByTagName('td');
        for (var j = 0; j < tdList.length; j++) {
            var td = tdList[j];
            var timeSpan = getMatchClassNameElement(td.getElementsByTagName('span'), 'time');
            if (!timeSpan)
                continue;
            //
            return timeSpan.innerText;
        }
    }
    /*获取:产品价格所在的元素(不直接获取innerText是为了方便获取产品数量)*/
    function getProductPriceElement(e) {
        var tdList = e.getElementsByTagName('td');
        for (var j = 0; j < tdList.length; j++) {
            var td = tdList[j];
            var tmp = getMatchClassNameElement(td.getElementsByTagName('div'), 'price');
            if (!tmp)
                continue;
            //
            return tmp;
        }
    }
    /*获取商品原始价格*/
    function getProductPriceDeletedElement(e) {
        var tdList = e.getElementsByTagName('td');
        for (var j = 0; j < tdList.length; j++) {
            var td = tdList[j];
            var tmp = getMatchClassNameElement(td.getElementsByTagName('del'), 'del');
            if (!tmp)
                continue;
            //
            return tmp;
        }
    }
    /*获取:产品数量(价格旁边的元素就是数量!)*/
    function getProductCount(priceItem) {
        var tr = priceItem.parentElement.nextElementSibling;
        return tr.innerText;
    }
    /*把元素列表中匹配指定innerText的元素取出来*/
    function getMatchInnerTextElement(items, innerText) {
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.innerText.length < innerText.length || item.innerText.indexOf(innerText) == -1)
                continue;
            //
            return item;
        }
    }
    function getProductProps(e) {
        var item = getMatchClassNameElement(e.getElementsByTagName('span'), 'sku');
        if (item && item.parentElement)
            return item.parentElement.innerText;
        return '';
    }
    //===============================================================
    /*把字符串转换为数字.*/
    function toNumber(e) {
        return Number(e.replace(/[^\d\.]/g, ''));
    }
    /*判断网址是否为产品详情页的网址*/
    function isProductItemDetailUrl(url) {
        var whiteList = ['========='//
            , '/item.htm?'//淘宝网
            , '/detail/view_detail.htm?'//天猫超市
        ];
        for (var i in whiteList)
            if (url.indexOf(whiteList[i]) > -1)
                return true;
        return false;
    }
    /*获取指定Tag的父节点元素*/
    function getMatchParentElement(e, tagName) {
        tagName = tagName.toLowerCase();
        if (e.tagName.toLowerCase() == tagName)
            return e;
        return getMatchParentElement(e.parentElement, tagName);
    }
    /*获取className包含指定字符串的元素*/
    function getMatchClassNameElement(items, className) {
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.className.indexOf(className) > -1)
                return item;
        }
    }
}
)();

(function () {
    if (window.location.host != 'mission.jianghu.taobao.com')
        return;
    //================================================================================
    // 05.淘金币“任务盒子”快速按键完成任务
    //================================================================================
    document.onkeydown = function (e) {
        console.dir(e);
        //捕获 ~ 按键
        if (e.keyCode != 192)
            return;

        //1.点击“继续完成任务”
        var items = document.getElementsByClassName('mission-popup-continue');
        if (items.length > 0) {
            console.dir('1.点击“继续完成任务”');
            console.dir("length " + items.length);
            //return;
            items[0].href = "javascript:void();";
            items[0].click();
            return;
        }

        //2.关闭领奖成功后的对话框
        var items = document.getElementsByClassName('mission-popup-close');
        if (items.length > 0) {
            console.dir('2.关闭领奖成功后的对话框');
            console.dir("length " + items.length);
            //return;
            items[0].click();
            return;
        }

        //3.点击“参加任务”或“领取奖品”
        var items = document.getElementsByClassName('action-button');
        if (items.length > 0) {
            console.dir('3.点击“参加任务”或“领取奖品”');
            console.dir("length " + items.length);
            //return;
            items[0].click();
            return;
        }
    }
        ;
}
)();
(function () {
    if (window.location.host != 's.taobao.com')
        return;
    YeScript.hideTabaoJinBiProductItem = function () {
        //================================================================================
        // 04.过滤掉 淘金币折扣率“小于50”的商品
        //================================================================================
        document.onkeydown = function (e) {
            //console.dir(e);
            //捕获 ~ 按键
            if (e.keyCode != 192)
                return;
            hideTabaoJinBiProductItem();
        }
            ;
        function hideTabaoJinBiProductItem() {
            var items = document.getElementsByClassName('icon-service-duliang');
            for (var i = 0; i < items.length; i++) {
                var item = items[i];
                var zks = /[^\d]+(\d+)[^\d]+/g.exec(item.innerText);
                if (!zks || zks.length != 2)
                    continue;
                var zk = parseInt(zks[1]);
                //console.log(zk);
                if (zk < 10)
                    hideItemByMatchAttribute(item, 'nid');
            }
        }
        //通过匹配 父级元素 是否具有某个 “特殊属性名称” 作为条件 来 隐藏元素
        function hideItemByMatchAttribute(e, value) {
            if (e == null)
                return;
            //有的自定义属性貌似无法通过attributes读取到。
            //var v = e.attributes[value];
            var v = e.getAttribute(value);
            //console.dir(v);
            if (!v)
                return hideItemByMatchAttribute(e.parentElement, value);
            e.hidden = !e.hidden;
        }
    }
        ;
    inject(YeScript.hideTabaoJinBiProductItem);
}
)();
(function () {
    if (window.location.host != 'detail.tmall.com' && window.location.host != 'item.taobao.com')
        return;
    YeScript.excludeOneDayPraise = function () {
        //================================================================================
        // 03.过滤掉“0日追评”
        //================================================================================
        document.ondblclick = function () {
            console.log('03.开始执行');
            doIt('tb-r-info', '0 天', 'li');
            doIt('tb-r-date', '0 天', 'li');
            doIt('tm-rate-daydiff', '当天', 'tr');
            function doIt(css, key, tag) {
                var items = document.getElementsByClassName(css);
                for (var i = 0; i < items.length; i++) {
                    var item = items[i];
                    if (item.innerText.indexOf(key) == -1)
                        continue;
                    ye(item, tag);
                    console.log('03.执行完毕');
                }
            }
            function ye(e, tag) {
                var p = e.parentElement;
                if (p == null)
                    return;
                if (p.tagName != tag.toUpperCase())
                    return ye(p, tag);
                p.hidden = true;
            }
        }
            ;
    }
        ;
    inject(YeScript.excludeOneDayPraise);
}
)();
(function () {
    YeScript.runRuYiTao = function () {
        //================================================================================
        // 02.“如意淘插件”增强版：点击“价格走向” 进入 “一淘返利”模式
        //================================================================================
        document.onkeydown = function (e) {
            //捕获 ~ 按键
            if (e.keyCode != 192)
                return;
            runRuYiTao();
            document.onkeydown = null;
        }
            ;
        function runRuYiTao() {
            var YETAG;
            YETAG = document.createElement('script');
            YETAG.type = 'text/javascript';
            YETAG.id = 'YEJS_' + +new Date();
            YETAG.onload = etaoFanLi;
            YETAG.src = 'http://ruyi.taobao.com/extension/bookmarklet.js?t=' + (+new Date()).toString().substring(0, 6);
            document.body.appendChild(YETAG);
        }
        function etaoFanLi(e) {
            //首先拿到nid
            var url = "";
            url += 'http://ruyi.taobao.com/ext/productLinkSearch?group=prices%2Citem&pid=rb001';
            url += '&callback=jQuery17107232299104798585_1404547929079';
            url += '&link=' + encodeURIComponent(window.location.href);
            url += '&_=' + +new Date();

            var YETAG;
            YETAG = document.createElement('script');
            YETAG.type = 'text/javascript';
            YETAG.id = 'YEJS_' + +new Date();
            YETAG.src = url;
            document.body.appendChild(YETAG);
        }
        window.jQuery17107232299104798585_1404547929079 = function (e) {
            //再拼接为返利界面网址
            var url = "";
            url += 'http://s.etao.com/detail/';
            url += e.Item.nid;
            url += ".html";
            //绑定按钮的点击事件，点击之后就开启计时器，直到找到助手的iFrame
            window.yeIntervalId = setInterval(function () {
                var div = document.getElementById('ruyitao-like-button-price-curve');
                if (!div)
                    return;
                div.onclick = function () {
                    window.location.href = url;
                }
                    ;
                clearInterval(window.yeIntervalId);
                console.log('02.功能完成。');
            }, 1000);
        }
            ;
    }
        ;
    switch (window.location.host) {
        case 'detail.tmall.com':
        case 'item.taobao.com':
            inject(YeScript.runRuYiTao);
            break;
        default:
            return;
    }
}
)();
(function () {
    if (window.location.host != 'item.taobao.com')
        return;
    YeScript.fixedSizeHelperPosition = function () {
        //================================================================================
        // 01.将“尺码助手”的位置固定住
        //================================================================================
        var btn = document.getElementById('J_TMySize');
        if (!btn) {
            console.log('01.没有找到“尺码助手”！');
            return;
        }
        btn.onclick = function (e) {
            //绑定按钮的点击事件，点击之后就开启计时器，直到找到助手的iFrame
            window.yeIntervalId = setInterval(function () {
                var div = document.getElementById('J_SizeIframeWrap');
                if (!div)
                    return;
                div.style.position = 'fixed';
                clearInterval(window.yeIntervalId);
                console.log('01.功能完成。');
            }, 1000);
        }
            ;
        console.log('01.绑定按钮click事件完成。');
    }
        ;
    inject(YeScript.fixedSizeHelperPosition);
}
)();